#include "ToolFunc.h"
#include <ctime>
#include <cstdlib>

CToolFunc::CToolFunc()
{
}

CToolFunc::~CToolFunc()
{
}

int CToolFunc::GetRandomNumber(int min, int max)
{
	srand(unsigned(timeGetTime() * timeGetTime()));
	return (min + rand() % (max - min));
}

#define FLOAT_INT_TEST  100000
float CToolFunc::GetRandomNumber(float min, float max)
{
	int left = int(min * FLOAT_INT_TEST);
	int right = int(max * FLOAT_INT_TEST);
	
	int res = GetRandomNumber(left, right);
	return float(res) / FLOAT_INT_TEST;
}

const WCHAR* CToolFunc::GetExeDir()
{
	static WCHAR s_szFilePath[MAX_PATH] = {};

	if (wcslen(s_szFilePath) > 0)
		return s_szFilePath;

	GetModuleFileNameW(NULL, s_szFilePath, MAX_PATH);

	int nLen = (int)wcslen(s_szFilePath);
	for (int i = nLen - 1; i >= 0; --i)
	{
		if (s_szFilePath[i] == '\\')
		{
			s_szFilePath[i + 1] = 0;
			break;
		}
	}

	return s_szFilePath;
}